package com.bobo.controller;


import com.bobo.pojo.ResposeResult;
import com.bobo.pojo.User;
import com.bobo.service.UserService;
import com.bobo.util.ForRepeatCommit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;


@Controller
public class UserController {

    @Autowired
    UserService userService;
    @GetMapping("add")//跳转到增加页面
    public String add(Model model){
        UUID token = UUID.randomUUID();
        model.addAttribute("token",token);
        return "add";
    }
    @ForRepeatCommit //标记为防重复提交注解
    @ResponseBody
    @PostMapping("add")//执行注册
    public Object add(User user){
        int i = userService.add(user);
        ResposeResult<User> result = new ResposeResult<User>();
        result.setCode(200);
        result.setMsg("保存成功");
        return result;
        }



    @ResponseBody
    @RequestMapping("get")
   public User get(){

       return userService.get(1);

    }


}
